package peng.yang.express.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

import peng.yang.express.Adapter.ExpressNameAdapter;
import peng.yang.express.Bean.PhoneMembers;
import peng.yang.express.R;
import peng.yang.express.Util.PhoneMembersDao;

public class ExpNameActivity extends AppCompatActivity {
    private final String Tag="ExpNameActivity";
    private ListView lv_name;
    private List<PhoneMembers> list;
    private PhoneMembersDao dao;
    private ExpressNameAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exp_name);
        initView();
        initData();
        initClick();
    }




    private void initView() {
        lv_name = (ListView) findViewById(R.id.lv_name);


    }

    private void initData() {
        dao = new PhoneMembersDao(this);
        list = dao.getAllMembers();
        adapter = new ExpressNameAdapter(this,list);
        lv_name.setAdapter(adapter);
    }

    private void initClick() {
        lv_name.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView sigleName= (TextView) view.findViewById(R.id.tv_sigleName);
                TextView expName= (TextView) view.findViewById(R.id.tv_expName);
                Intent intent = new Intent();
                intent.putExtra("sigleName",  sigleName.getText().toString());
                intent.putExtra("expName",expName.getText().toString());
                Log.e(Tag,sigleName.getText().toString());
                setResult(21,intent);
                finish();
            }
        });
    }


}
